package io.bdmc.modules.bss.controller;

import io.bdmc.common.annotation.SysLogger;
import io.bdmc.common.utils.MyPage;
import io.bdmc.common.utils.R;
import io.bdmc.modules.bss.entity.DeviceAlarmType;
import io.bdmc.modules.bss.model.DeviceAlarmTypeParam;
import io.bdmc.modules.bss.service.IDeviceAlarmTypeService;
import io.bdmc.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 设备报警类型表 前端控制器
 * </p>
 *
 * @author 黄露
 * @since 2020-08-11
 */

// "设备报警类型表", description = "接口地址：/bss/alarm/type")
@RestController
@RequestMapping("/bss/alarm/type")
public class DeviceAlarmTypeController extends AbstractController {

	@Autowired
	IDeviceAlarmTypeService _devicealarmtypeSvs;

	@GetMapping("/list")
	// "查询设备报警类型", notes = "查询设备报警类型")
	public R list(DeviceAlarmTypeParam params) {
		MyPage<DeviceAlarmType> myPage = new MyPage<DeviceAlarmType>(params.getCurrent(), params.getSize());
		myPage = _devicealarmtypeSvs.mySelectPage(myPage, params);
		return R.ok().putPageData(myPage.getRecords(), myPage.getTotal());
	}

	@SysLogger("新增设备报警类型")
	@PostMapping("/add")
	// "新增设备报警类型", notes = "新增设备报警类型")
	@RequiresPermissions("bss:alarm:type:add")
	public R add(@RequestBody DeviceAlarmType devicealarmtype) {
		devicealarmtype.setCreateBy(getUser().getUsername());
		devicealarmtype.setCreateTime(LocalDateTime.now());
		devicealarmtype.setEnabled(true);
		Boolean b = devicealarmtype.insert();
		return R.trueOrFalse(b);
	}

	@SysLogger("修改设备报警类型")
	@PostMapping("/update")
	// "修改设备报警类型", notes = "修改设备报警类型")
	@RequiresPermissions("bss:alarm:type:update")
	public R update(@RequestBody DeviceAlarmType devicealarmtype) {
		Boolean b = devicealarmtype.updateById();
		return R.trueOrFalse(b);
	}

	@SysLogger("删除设备报警类型")
	@DeleteMapping("/delete/{alarmTypeId}")
	// "删除设备报警类型", notes = "删除设备报警类型")
	@RequiresPermissions("bss:alarm:type:delete")
	public R delete(@PathVariable Integer alarmTypeId) {
		if (alarmTypeId > 0)
			_devicealarmtypeSvs.removeById(alarmTypeId);
		return R.ok();
	}

	@GetMapping("combo")
	public R combo() {

		return R.ok().putData(_devicealarmtypeSvs.combo());
	}
}
